package tools

import (
	"encoding/json"
	"regexp"
)

// replace 正则语法：一般是正则匹配替换
func (a *Argument) replace() {
	var in = struct {
		Matching string `json:"matching"`
		Replace  string `json:"replace"`
	}{}
	bytes, _ := json.Marshal(a.Function.Parameter)
	err := json.Unmarshal(bytes, &in)
	if err != nil {
		return
	}
	v := a.Value
	if in.Matching != "" {
		reg := regexp.MustCompile(in.Matching)
		reg.ReplaceAllString(v, in.Replace)
	}
	a.Value = v
}
